home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 2 / Mac Magazin and MacEasy Magazine CD - Issue 02.iso / Sharewarebibliothek / Applikationen / Alpha.5.81 folder / Tcl / SystemCode / wordCompletion.tcl < prev   
Text File  |  1994-04-27  |  3KB  |  82 lines

  1. #===========================================================================
  2. # 'Word Completion, in the spirit of Paul van Mulbregt's BBXT.
  3. # Composed by Mark Nagata (nagata@kurims.kyoto-u.ac.jp) 
  4. # for Alpha 5.76, 4/22/94.
  5. #================================================================================
  6.  
  7. proc wordCompletion {} {
  8.     set pos [getPos]
  9.     backwardWord
  10.     set start [getPos]
  11.     set one [getText $start $pos]
  12.     set len [expr $pos-$start]
  13.     set pat [append one {[a-zA-Z0-9_]+}]
  14.     set start [expr $start-1]
  15.     if {![catch {search -f 0 -r 1 -i 0 -m 1 -- $pat $start} data]} {
  16.         set beg [expr [lindex $data 0]+$len]
  17.         set end [lindex $data 1]
  18.         set txt [getText $beg $end]
  19.         goto $pos
  20.         insertText $txt
  21.         message "found above."
  22.         return
  23.     }
  24.     if {![catch {search -f 1 -r 1 -i 0 -m 1 -- $pat $pos} data]} {
  25.         set beg [expr [lindex $data 0]+$len]
  26.         set end [lindex $data 1]
  27.         set txt [getText $beg $end]
  28.         goto $pos
  29.         insertText $txt
  30.         message "found below."
  31.         return
  32.     }
  33.     goto $pos
  34.     backwardWordSelect
  35. }
  36.  
  37. bind  F1     wordCompletion 
  38.  
  39.  
  40. # This is all due to the idea of Paul van Mulbregt. In his documentation 
  41. # of his BBEdit BBExtension (info-mac/text/bbedit-fl-package-11.hqx), 
  42. # he explains:
  43. # --  From the documentation written by        --
  44. # --  Paul van Mulbregt (paulvm@dragonsys.com) --
  45. # Word Completion
  46. # This extension saves typing, as well as making sure variable names are 
  47. # correct.  While typing the following C code, there is no need to type all 
  48. # of the second occurrence of verySpecialInt.  One could copy and paste, but 
  49. # another way is to type a few letters, and select the Word Completion 
  50. # Extension.
  51. #     int verySpecialInt = 10;
  52. #     while(verySp                                                    
  53. # becomes
  54. #     int verySpecialInt = 10;
  55. #     while(verySpecialInt                                             
  56. #                                                     
  57. # Word Completion will look back in the code to find the first match and then 
  58. # extend the current occurrence to match the previous occurrence.  If a match 
  59. # is not found looking backwards, then it looks forwards.  If not found 
  60. # forwards, the word is selected.  This is a quick way to save on typing, 
  61. # good for helping prevent RSI, but perhaps more importantly, to make sure 
  62. # that variable names are spelt correctly.
  63. # There is no user interface for Word Completion.
  64. # The usefulness of this extension is greatly enhanced if the extension is 
  65. # bound to a key!
  66. # -- end of Paul van Mulbregt's explanation. --
  67.  
  68.